#pragma once;

#include <Windows.h>

namespace SysInfos
{

	//////////////////////////////////////////////////////////////////////////
	// class CMemoryDetail
	//

	class CMemoryDetail
	{
	public:
		CMemoryDetail(const MEMORYSTATUSEX& memStatus): m_memStatus(memStatus) {}

		CMemoryDetail() 
		{
			UpdateMemInfo();
		}
	public:
		DWORDLONG GetTotalPhysicMemory()
		{
			return GetMemInfo().ullTotalPhys;
		}

		DWORDLONG GetAvailablePhysicMemory()
		{
			return GetMemInfo().ullAvailPhys;
		}

		DWORDLONG GetTotalVirtualMemory()
		{
			return GetMemInfo().ullTotalVirtual;
		}

		DWORDLONG GetAvailableVirtualMemory()
		{
			return GetMemInfo().ullAvailVirtual;
		}

		DWORDLONG GetTotalPageFileMemory()
		{
			return GetMemInfo().ullTotalPageFile;
		}

		DWORDLONG GetAvailablePageFileMemory()
		{
			return GetMemInfo().ullAvailPageFile;
		}

		DWORDLONG GetAvailableCommitChargeMemory()
		{
			MEMORYSTATUSEX state = GetMemInfo();
			DWORDLONG ullUsedFP = state.ullTotalPageFile - state.ullAvailPageFile;
			if(state.ullTotalPhys > ullUsedFP )
				return state.ullTotalPhys - ullUsedFP;
			return 0;
		}

		MEMORYSTATUSEX GetMemInfo() const
		{
			return m_memStatus;
		}

		void UpdateMemInfo()
		{
			m_memStatus.dwLength = sizeof (m_memStatus);
			GlobalMemoryStatusEx(&m_memStatus);
		}

	private:
		MEMORYSTATUSEX	m_memStatus;

	};

	//////////////////////////////////////////////////////////////////////////
	// class CSystemInfo
	//

	class CSystemInfo
	{
	public:
		CSystemInfo(const SYSTEM_INFO& sysInfo): m_sysInfo(sysInfo) {}
		CSystemInfo()
		{
			UpdateSystemInfo();
		}

		SYSTEM_INFO GetSysInfo() const { return m_sysInfo; }

		int GetProcessorNumbers() const { return m_sysInfo.dwNumberOfProcessors; }

		void UpdateSystemInfo()
		{
			GetSystemInfo(&m_sysInfo);
		}

	private:
		SYSTEM_INFO	m_sysInfo;
	};

}